package com.rcw.filelib.bean;

import android.os.Parcel;
import android.os.Parcelable;


import com.rcw.filelib.FileType;
import com.rcw.filelib.Utils;

import java.io.File;


/**
 * Created by droidNinja on 29/07/16.
 */
public class Document extends BaseFile {
    private String mimeType;
    private String size;
    private FileType fileType;
    private String fileUrl;
    private String mdFileName;

    public String getMdFileName() {
        return mdFileName;
    }

    public void setMdFileName(String mdFileName) {
        this.mdFileName = mdFileName;
    }

    public String getFileUrl() {
        return fileUrl;
    }

    public void setFileUrl(String fileUrl) {
        this.fileUrl = fileUrl;
    }

    public Document(int id, String title, String path) {
        super(id, title, path);
    }

    public Document() {
        super(0, null, null);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Document)) return false;

        Document document = (Document) o;

        return id == document.id;
    }

    @Override
    public int hashCode() {
        return id;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    public String getTitle() {
        return new File(this.path).getName();
    }

    public void setTitle(String title) {
        this.name = title;
    }

    public boolean isThisType(String[] types) {
        return Utils.contains(types, this.path);
    }

    public FileType getFileType() {
        return fileType;
    }

    public void setFileType(FileType fileType) {
        this.fileType = fileType;
    }

    @Override
    public String toString() {
        return "Document{" +
                "mimeType='" + mimeType + '\'' +
                ", size='" + size + '\'' +
                ", fileType=" + fileType +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeString(this.mimeType);
        dest.writeString(this.size);
        dest.writeParcelable(this.fileType, flags);
        dest.writeString(this.fileUrl);
        dest.writeString(this.mdFileName);
    }

    protected Document(Parcel in) {
        super(in);
        this.mimeType = in.readString();
        this.size = in.readString();
        this.fileType = in.readParcelable(FileType.class.getClassLoader());
        this.fileUrl = in.readString();
        this.mdFileName = in.readString();
    }

    public static final Parcelable.Creator<Document> CREATOR = new Parcelable.Creator<Document>() {
        @Override
        public Document createFromParcel(Parcel source) {
            return new Document(source);
        }

        @Override
        public Document[] newArray(int size) {
            return new Document[size];
        }
    };
}
